package com.wwwarehouse.common.activity.tempcardlist;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.wwwarehouse.common.R;
import com.wwwarehouse.common.activity.base.BaseFragment;

import java.util.LinkedList;


public class TempCardListFragment extends BaseFragment {

    private TextView mTempCardlistTxtId;
    private View mTempCardlistViewId;
    private RecyclerView mTempCardlistRecycleviewId;
    View v = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.activity_temp_card_list, container, false);
        return v;
    }

    @Override
    public void requestDatas() {
        initView();
    }

    private void initView() {
        mTempCardlistViewId = v.findViewById(R.id.temp_cardlist_view_id);
        mTempCardlistRecycleviewId = (RecyclerView) v.findViewById(R.id.temp_cardlist_recycleview_id);

        mTempCardlistRecycleviewId.setLayoutManager(new LinearLayoutManager(getActivity()));

        LinkedList<MyBean> list = new LinkedList<>();
        MyBean myBean;

        myBean = new MyBean();
        myBean.setTitle("登录页面");
        myBean.setBean("/UserCenter/LoginActivity");
        list.add(myBean);

        //以下全部替换成路径跳转
//        myBean = new MyBean();
//        myBean.setTitle("电商铺货");
//        ReleaseDistributionFragment releaseDistributionFragment = new ReleaseDistributionFragment();
//        Bundle bundle = new Bundle();
//        bundle.putInt("temp", 1);
//        releaseDistributionFragment.setArguments(bundle);
//        myBean.setBean(releaseDistributionFragment);
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("线下铺货");
//        ReleaseDistributionFragment releaseDistributionFragment2 = new ReleaseDistributionFragment();
//        Bundle bundle2 = new Bundle();
//        bundle2.putInt("temp", 2);
//        releaseDistributionFragment2.setArguments(bundle2);
//        myBean.setBean(releaseDistributionFragment2);
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("提供服务");
//        myBean.setBean(new ReleaseProviedServerFragment());
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("激活店铺");
//        myBean.setBean(new ActivateStoreFragment());
//        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("完善信息");
        myBean.setBean("/UserCenter/SystemServiceActivity");
        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("保存往来单位");
//        myBean.setBean(new AddCurrUnitFragment());
//        list.add(myBean);
//
//        myBean = new MyBean();
//        myBean.setTitle("修改往来单位");
//        myBean.setBean(new ModCurrUnitFragment());
//        list.add(myBean);
//
//        myBean = new MyBean();
//        myBean.setTitle("激活仓库");
//        myBean.setBean(new ActivateWarehouseFragment());
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("接口调试");
//        myBean.setBean(TestActivity.class);
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("GPS地图");
//        myBean.setBean(MapActivity.class);
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("连接设备");
//        myBean.setBean(new ConnectDeviceFragment());
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("测试指环");
//        myBean.setBean(new TestBluethoothRingFragment());
//        list.add(myBean);
//
//        myBean = new MyBean();
//        myBean.setTitle("测试设备");
//        myBean.setBean(new TestDeviceFragment());
//        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("邀请注册");
        Fragment inviteRegisterFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/InviteRegisterFragment")
                .navigation();
        myBean.setBean(inviteRegisterFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("同意接受邀请");
        Fragment agree2AcceptInviteFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/Agree2AcceptInviteFragment")
                .navigation();
        myBean.setBean(agree2AcceptInviteFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("注册-拼卡界面");
        myBean.setBean("/UserCenter/RegisterCardActivity");
        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("设置");
//        Fragment setFragment = (Fragment) ARouter.getInstance()
//                .build("/group1/SetFragment")
//                .navigation();
//        myBean.setBean(setFragment);
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("新建任务分配规则");
//        myBean.setBean(new SetRulesFragment());
//        list.add(myBean);
//
//        myBean = new MyBean();
//        myBean.setTitle("创建顶级业务单位");
//        myBean.setBean(new CreateBusinessUnitFragment());
//        list.add(myBean);

//        myBean = new MyBean();
//        myBean.setTitle("审核被邀请人");
//        myBean.setBean(ReviewInviteeFragment.newInstance());
//        list.add(myBean);
//
        myBean = new MyBean();
        myBean.setTitle("修改注册信息");
        Fragment modifyRegisterInfoFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/ModifyRegisterInfoFragment")
                .navigation();
        myBean.setBean(modifyRegisterInfoFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("订单导入设置(任务卡片)");
        Fragment importOrders1 = (Fragment) ARouter.getInstance()
                .build("/contract/ImportOrdersPagersPagerFragment")
                .withInt("type", 1)
                .navigation();
        myBean.setBean(importOrders1);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("修改契约导入");
        Fragment importOrders2 = (Fragment) ARouter.getInstance()
                .build("/contract/ImportOrdersPagersPagerFragment")
                .withInt("type", 2)
                .navigation();
        myBean.setBean(importOrders2);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("测试分享");
        Fragment testFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/TestShareFragment")
                .navigation();
        myBean.setBean(testFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("创建三角链");
        Fragment tcFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/TriangulationChainFragment")
                .navigation();
        myBean.setBean(tcFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("管理三角链");
        Fragment tcgFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/TCAuthenticationFragment")
                .navigation();
        myBean.setBean(tcgFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("手机转PC");
        Fragment pcToMobilFragment = (Fragment) ARouter.getInstance()
                .build("/contract/TestFragment")
                .navigation();
        myBean.setBean(pcToMobilFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("订单获取监控");
        Fragment monitorFragment = (Fragment) ARouter.getInstance()
                .build("/contract/ImportOrdersMonitorPagerFragment")
                .navigation();
        myBean.setBean(monitorFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("创建顶级业务单位");
        Fragment createBusinessUnitFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/CreateBusinessUnitFragment")
                .navigation();
        myBean.setBean(createBusinessUnitFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("邀请的顶级业务单位");
        Fragment businessUnitInfoFragment = (Fragment) ARouter.getInstance()
                .build("/UserCenter/BusinessUnitInfoFragment")
                .navigation();
        myBean.setBean(businessUnitInfoFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("顶级业务单位信息卡片");
        Fragment businessInfoViewPagerFragment = (Fragment) ARouter.getInstance().build("/UserCenter/BusinessInfoViewPagerFragment").navigation();
        myBean.setBean(businessInfoViewPagerFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("创建物");
        Fragment createObjectFragment = (Fragment) ARouter.getInstance()
                .build("/ResourceCenter/CreateObjectFragment")
                .navigation();
        myBean.setBean(createObjectFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("创建资源");
        Fragment createResFragment = (Fragment) ARouter.getInstance()
                .build("/ResourceCenter/CreateResFragment")
                .navigation();
        myBean.setBean(createResFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("权限分配假入口");
        Fragment fakeAuthEntranceFragment = (Fragment) ARouter.getInstance().build("/UserCenter/FakeAuthorityEntranceFragment").navigation();
        myBean.setBean(fakeAuthEntranceFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("蓝牙测试");
        Fragment bluetoothFragment = (Fragment) ARouter.getInstance().build("/ResourceCenter/BluetoothFragment").navigation();
        myBean.setBean(bluetoothFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("权限回收");
        Fragment prFragment = (Fragment) ARouter.getInstance().build("/UserCenter/PRFragment").navigation();
        myBean.setBean(prFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("新增单位");
        Fragment newUnitFragment = (Fragment) ARouter.getInstance().build("/ResourceCenter/NewUnitFragment").navigation();
        myBean.setBean(newUnitFragment);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("修改单位");
        Fragment updateUnitViewPagerFragment = (Fragment) ARouter.getInstance().build("/ResourceCenter/UpdateUnitViewPagerFragment").navigation();
        myBean.setBean(updateUnitViewPagerFragment);
        list.add(myBean);

        MyAdapter myAdapter = new MyAdapter(getActivity(), list);
        mTempCardlistRecycleviewId.setAdapter(myAdapter);
        myAdapter.notifyDataSetChanged();
    }

    @Override
    public void setTitle() {
        mActivity.setTitle(R.string.function_info);
    }

    class MyAdapter extends RecyclerView.Adapter {
        private Context context;
        private View view;
        private LinkedList<MyBean> list;

        public MyAdapter(Context context, LinkedList<MyBean> list) {
            this.context = context;
            this.list = list;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            view = LayoutInflater.from(context).inflate(R.layout.demo_show_item_adapter_item, parent, false);
            final MyHolder viewHolder = new MyHolder(view);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
            final MyBean myBean = list.get(position);
            ((MyHolder) holder).myTextView.setText(myBean.getTitle());
            ((MyHolder) holder).myRel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (myBean.getBean() instanceof Fragment) {
                        pushFragment((Fragment) myBean.getBean());
                    } else {
                        startActivity((String) myBean.getBean(), null, false);
                    }

                }
            });
        }

        @Override
        public int getItemCount() {
            if (list == null) {
                return 0;
            } else {
                return list.size();
            }
        }

        class MyHolder extends RecyclerView.ViewHolder {
            private TextView myTextView;
            private RelativeLayout myRel;

            public MyHolder(View itemView) {
                super(itemView);
                myRel = (RelativeLayout) view.findViewById(R.id.desk_adapter_rel);
                myTextView = (TextView) view.findViewById(R.id.desk_adapter_txt_id);
            }
        }
    }

    class MyBean<T> {
        private String title;
        private T bean;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public T getBean() {
            return bean;
        }

        public void setBean(T bean) {
            this.bean = bean;
        }
    }
}
